import dayjs from "dayjs";


export function friendly_datetime(now: dayjs.Dayjs, time: dayjs.Dayjs): string {
  if (time.year() != now.year()) {
    return time.format('YYYY年M月D日');
  } else if (time.month() != now.month() || time.date() != now.date()) {
    return time.format('M月D日');
  } else {
    return friendly_time(time)
  }
}
export function friendly_time(time: dayjs.Dayjs): string {
  const h = time.hour();
  if (h < 6) {
    return '凌晨 ' + time.format(`h:mm`);
  } else if (h < 9) {
    return '早上 ' + time.format(`h:mm`);
  } else if (h < 12) {
    return '上午 ' + time.format(`h:mm`);
  } else if (h < 13) {
    return '中午 ' + time.format(`h:mm`);
  } else if (h < 18) {
    return '下午 ' + time.format(`h:mm`);
  } else {
    return '晚上 ' + time.format(`h:mm`);
  }
}

export function friendly_datetime_2(now: dayjs.Dayjs, time: dayjs.Dayjs): string {
  if (time.year() != now.year()) {
    return time.format('YYYY年M月D日') + friendly_time(time);
  } else if (time.month() != now.month() || time.date() != now.date()) {
    return time.format('M月D日') + friendly_time(time);
  } else {
    return friendly_time(time)
  }
}